package com.teradata.olingo.processor.core.query;

import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath;
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument;
import org.apache.olingo.server.api.ODataApplicationException;

import java.util.List;

public final class GenericExpandItemInfo extends GenericInlineItemInfo {

  GenericExpandItemInfo(final JPAServiceDocument sd, final GenericExpandItem uriInfo,
                        final JPAAssociationPath expandAssociation, final List<GenericNavigationProptertyInfo> hops)
      throws ODataApplicationException {

    super(uriInfo, expandAssociation);

    for (GenericNavigationProptertyInfo predecessor : hops)
      this.hops.add(new GenericNavigationProptertyInfo(predecessor));
    this.hops.get(this.hops.size() - 1).setAssociationPath(expandAssociation);
    if (!uriInfo.getUriResourceParts().isEmpty())
      this.hops.addAll(Util.determineNavigationPath(sd, uriInfo.getUriResourceParts(), uriInfo));
    else
      this.hops.add(new GenericNavigationProptertyInfo(sd, null, uriInfo, uriInfo.getEntityType()));
  }
}
